package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.CornerPathEffect
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* VideoVipView
* */
class VideoVipView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            //strokeWidth = context.resources.getDimension(R.dimen.dp_2)
            //style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_4260F4)
        }
    }

    private val mPaint1 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            //strokeWidth = context.resources.getDimension(R.dimen.dp_2)
            //style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_42F498)
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)
            mPath.apply {
                reset()
                moveTo(-cx, cy * 5 / 6)
                lineTo(-cx, -cy * 5 / 6)
                arcTo(
                    -cx,
                    -cy,
                    -cx * 2 / 3,
                    -cy * 2 / 3,
                    180F,
                    90F,
                    false
                )
                lineTo(cx * 5 / 6, -cy)
                arcTo(
                    cx * 2 / 3,
                    -cy ,
                    cx,
                    -cy * 2 / 3,
                    270F,
                    90F,
                    false
                )
                lineTo(cx, cy * 5 / 6)
                arcTo(
                    cx * 2 / 3,
                    cy * 2 / 3,
                    cx,
                    cy,
                    0F,
                    90F,
                    false
                )
                lineTo(-cx * 5 / 6, cy)
                arcTo(
                    -cx,
                    cy * 2 / 3,
                    -cx * 2 / 3,
                    cy,
                    90F,
                    90F,
                    false
                )
            }
            drawPath(mPath, mPaint0)

            mPath.apply {
                reset()
                moveTo(0F, -cy)
                lineTo(cx * 5 / 6, -cy)
                arcTo(
                    cx * 2 / 3,
                    -cy ,
                    cx,
                    -cy * 2 / 3,
                    270F,
                    90F,
                    false
                )
                lineTo(cx, -cy / 2)
                lineTo(cx / 3, -cy / 2)
                arcTo(
                    0F,
                    -cy * 5 / 6 ,
                    cx / 3,
                    -cy / 2,
                    90F,
                    90F,
                    false
                )
                close()
            }
            drawPath(mPath, mPaint1)
        }
    }
}